
package com.chy.utilsdemo.statistics;


import com.chy.utilsdemo.DateUtils.DateUtils;
import com.chy.utilsdemo.statistics.model.CountVo;

import java.util.ArrayList;
import java.util.List;

/**
 * 功能： 大屏  统计数据，按近七日、近六月、近六年
 *
 * ──────────────────────────────────────────
 *   version  变更日期    修改人    修改说明
 * ------------------------------------------
 *   V1.0.0   2021/11/1     CHY     初版
 * ──────────────────────────────────────────
 * @author chy
 */
public class StatisticsTest {
    public static void main(String[] args) {
        //近七日
        //dayList数据可以通过按时间分组查询数据而得，目前暂时使用模拟数据
        List<CountVo> dayList = selectDataByDayAndMonthAndYear("1");
        System.out.println("近七日");
        dayList.stream().forEach(e -> System.out.println(e));
        System.out.println();
        //近六月
        //monthList数据可以通过按时间分组查询数据而得，目前暂时使用模拟数据
        List<CountVo> monthList = selectDataByDayAndMonthAndYear("2");
        System.out.println("近六月");
        monthList.stream().forEach(e -> System.out.println(e));
        System.out.println();
        //近六年
        //yearList数据可以通过按时间分组查询数据而得，目前暂时使用模拟数据
        List<CountVo> yearList = selectDataByDayAndMonthAndYear("3");
        System.out.println("近六年");
        yearList.stream().forEach(e -> System.out.println(e));
        System.out.println();
    }

    /**
     * 统计数据，按近七日、近六月、近六年
     */
    public static List<CountVo> selectDataByDayAndMonthAndYear(String type){
        List<CountVo> list = new ArrayList<>();
        //1.显示近七日情况
        if (type.equals("1")){
            List<CountVo> dayList = getAnalysisByDay();
            List<String> sevenDate = DateUtils.getSevenDate();
            list = getAnalysisByType(dayList,sevenDate);
        }
        //2.显示近六个月情况
        else if (type.equals("2")){
            List<CountVo> monthList = getAnalysisByMonth();
            List<String> lastSixMonthData = DateUtils.getLastSixMonthDate();
            list = getAnalysisByType(monthList,lastSixMonthData);
        }
        //3.显示近六年情况
        else if (type.equals("3")){
            List<CountVo> yearList = getAnalysisByYear();
            List<String> lastSixYearDate = DateUtils.getLastSixYearDate();
            list = getAnalysisByType(yearList,lastSixYearDate);
        }
        return list;

    }

    public static List<CountVo> getAnalysisByType(List<CountVo> dataList,List<String> dateList){
        List<CountVo> list = new ArrayList<>();
        for (String d:dateList
        ) {
            Boolean flag = false;
            for (CountVo vo:dataList
            ) {
                if (d.equals(vo.getTime())){
                    list.add(new CountVo(d,vo.getNum()));
                    flag = true;
                    break;
                }
            }
            if (!flag){
                list.add(new CountVo(d,0));
            }
        }
        return list;
    }
    
    public static List<CountVo> getAnalysisByDay(){
        List<CountVo> list = new ArrayList<>();
        list.add(new CountVo("2021-11-01",20));
        list.add(new CountVo("2021-10-31",20));
        list.add(new CountVo("2021-10-30",20));
        list.add(new CountVo("2021-10-29",20));
        return list;
    }

    public static List<CountVo> getAnalysisByMonth(){
        List<CountVo> list = new ArrayList<>();
        list.add(new CountVo("2021-11",20));
        list.add(new CountVo("2021-10",20));
        list.add(new CountVo("2021-09",20));
        list.add(new CountVo("2021-08",20));
        return list;
    }

    public static List<CountVo> getAnalysisByYear(){
        List<CountVo> list = new ArrayList<>();
        list.add(new CountVo("2021",20));
        list.add(new CountVo("2020",20));
        list.add(new CountVo("2019",20));
        list.add(new CountVo("2018",20));
        return list;
    }
}
